aboutsummaryrefslogtreecommitdiff
path: root/src/routes/events/group/[group]/+page.svelte
blob: 7cd371009141e481459ec26afedcd3b9700077bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<script lang="ts">
	import type { Group } from '$lib/Database/groups';
	import type { Event } from '$lib/Database/events';
	import Message from '$lib/Loading/Message.svelte';
	import tooltip from '$lib/Tooltip/tooltip';
	import root from '$lib/Utility/root';
	import { onMount } from 'svelte';
	import locale from '$stores/locale.js';

	export let data;

	let groupsResponse: Promise<Response>;

	onMount(async () => {
		groupsResponse = fetch(root(`/api/events/group?slug=${data.group}`));
	});

	const asGroup = (group: any) => group as Group;

	const asEvent = (event: any) => event as Event;
</script>

{#await groupsResponse}
	<Message message="Loading group ..." />
{:then group}
	{#if group}
		{#await group.json()}
			<Message message="Parsing group ..." />
		{:then json}
			{#if json === null}
				<Message message="" loader="ripple" slot>
					This group may not exist. Please
					<a href={'#'} on:click={() => location.reload()}>try again</a> later.
				</Message>
			{:else}
				{@const group = asGroup(json)}

				<div
					class="card"
					id="user-grid"
					style={`background-image: ${group.banner ? `url(${group.banner})` : 'none'}; padding: 0;`}
				>
					{#if group}
						<img src={group.banner} alt="" id="cover-image" />
					{/if}

					<div class="card" id="user-grid-content">
						<div id="user-grid-avatar">
							<a href={`https://anilist.co/user/${group.anilist_username}`} target="_blank">
								<img src={group.avatar} alt="" width="100vw" id="avatar" />
							</a>
						</div>

						<div id="user-grid-content-text">
							<p>
								<a
									href={`https://anilist.co/user/${group.anilist_username}`}
									target="_blank"
									title={String(group.anilist_id)}
									use:tooltip
								>
									@{group.name}
								</a>
								{#if group && group.badge}
									&#8204;
									<button
										class="unclickable-button button-badge badge-rainbow"
										title={group.badge_description}
										use:tooltip
										data-tooltip-disable={group.badge_description}
									>
										{group.badge}
									</button>
								{/if}
							</p>

							<p>
								{group.description}
							</p>
						</div>
					</div>
				</div>

				<p />

				<details open>
					<summary>Events</summary>

					{#await fetch(root(`/api/events?group=${data.group}`))}
						<Message message="Loading events ..." />
					{:then eventsResponse}
						{#await eventsResponse.json()}
							<Message message="Parsing events ..." />
						{:then events}
							{#if events}
								{#each events as rawEvent}
									{@const event = asEvent(rawEvent)}

									<a href={event.anilist_url} target="_blank">
										<div
											class="card"
											id="user-grid"
											style={`background-image: ${
												event.banner ? `url(${event.banner})` : 'none'
											}; padding: 0;`}
										>
											{#if event}
												<img src={event.banner} alt="" id="cover-image" />
											{/if}

											<div class="card" id="user-grid-content">
												<div id="user-grid-content-text">
													<p>
														<a href={event.anilist_url} target="_blank" class="title-text">
															{event.title}
														</a>
														<br />
														{$locale().dateFormatter(new Date(event.created_at))}
													</p>

													<p>{event.description}</p>
												</div>
											</div>
										</div>
									</a>
								{/each}
							{/if}
						{:catch}
							<Message message="" loader="ripple" slot>
								Error parsing events. Please
								<a href={'#'} on:click={() => location.reload()}>try again</a> later.
							</Message>
						{/await}
					{/await}
				</details>
			{/if}
		{:catch}
			<Message message="" loader="ripple" slot>
				Error parsing group. Please
				<a href={'#'} on:click={() => location.reload()}>try again</a> later.
			</Message>
		{/await}
	{:else}
		<Message message="Parsing groups ..." />
	{/if}
{:catch}
	<Message message="" loader="ripple" slot>
		Error loading group. Please
		<a href={'#'} on:click={() => location.reload()}>try again</a> later.
	</Message>
{/await}

<style>
	#user-grid-content {
		display: flex;
		flex-wrap: wrap;
		column-gap: 1.5em;
		background-color: rgba(0, 0, 0, 0.468);
		color: #d8d8d8;
		border-top-left-radius: 0;
		border-top-right-radius: 0;
	}

	#user-grid-avatar {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	#avatar {
		border-radius: 8px;
	}

	/* .click-item {
		margin: 0 0.625rem;
	} */

	#user-grid {
		background-size: cover;
		background-position: center;
		background-repeat: no-repeat;
	}

	#cover-image {
		visibility: hidden;
		height: 4.5em;
	}

	.title-text {
		font-size: 1.1em;
	}
</style>